package com.kuzlak.cms.component;


import com.kuzlak.cms.config.ConstantHeader;
import com.kuzlak.cms.module.sys.service.SysSettingsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class PublicUtils {

    @Autowired
    private SysSettingsService settingsService;


    public Object getSetting(String key) {
        Object result = null;
        if (ConstantHeader.getSetting() != null) {
            if (ConstantHeader.getSetting().containsKey(key)) {
                result = ConstantHeader.getSetting().get(key);
            }
        } else {
            Map<String, Object> list = settingsService.findByKeys();
            if (list.containsKey(key)) {
                result = list.get(key);
            }
            ConstantHeader.setSetting(list);
        }
        return result;

    }


}
